package com.cycling.app.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.cycling.app.R;
import com.cycling.app.bean.User;
import com.cycling.app.utils.DribblePrefs;

/**
 * Created by ZhouLei on 2017/5/6.
 */

public class LoginActivity extends BaseActivity {

    private EditText edit_account;
    private EditText edit_pass;

    @Override
    public int layoutResId() {
        return R.layout.activity_login;
    }

    @Override
    public void onActivityCreate(@Nullable Bundle savedInstanceState) {
        setTitle("登录");
        edit_account = (EditText) findViewById(R.id.edit_account);
        edit_pass = (EditText) findViewById(R.id.edit_password);
    }

    public void jumpToRegister(View view) {
        startActivityForResult(new Intent(LoginActivity.this, RegisterActivity.class), 11);
    }

    public void loginNow(View view) {
        String account = edit_account.getText().toString();
        String pass = edit_pass.getText().toString();
        String msg = TextUtils.isEmpty(account) ? "请输入用户名或手机号"
                : TextUtils.isEmpty(pass) ? "请输入密码" : "";
        if (!TextUtils.isEmpty(msg)) {
            Toast.makeText(LoginActivity.this, msg, Toast.LENGTH_SHORT).show();
            return;
        }

        DribblePrefs.get().login(new User(1, account, "", 100.00d));
        Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 11 && resultCode == RESULT_OK) {
            finish();
        }
    }
}
